﻿using System.Web.Mvc;

namespace Supermodel.MVC.Extensions
{
    public static class MvcHtmlExtensions
    {
        public static MvcHtmlString DisableAllControls(this MvcHtmlString mvcStr)
        {
            return MvcHtmlString.Create(mvcStr.ToString().Replace("<input ", "<input disabled ").Replace("<textarea ", "<textarea disabled ").Replace("<select ", "<select disabled ").Replace("<a ", "<a disabled "));
        }

        public static MvcHtmlString MakeRequired(this MvcHtmlString mvcStr)
        {
            return MvcHtmlString.Create(mvcStr.ToString().Replace("class=\"", "class=\"required "));
        }

        public static string ToStringHandleNull(this MvcHtmlString mvcStr)
        {
            if (mvcStr != null) return mvcStr.ToString();
            return "";
        }
    }
}
